
let dateFormat = require('../../utils/util');

Page({
  data:{
    date: new Date(),
    year:new Date().getFullYear(),
    month: new Date().getMonth() + 1,
    day: new Date().getDate(),
    weeks_ch:['日', '一', '二', '三', '四', '五', '六'],
},
onReady() {
    let year = this.data.year;
    let month = this.data.month;
    let day = this.data.day;
    this.showday();
  },
showday(){
    //显示相应月份的天数
    this.count();
    let fistDate = new Date(this.data.year, this.data.month - 1, 1);
    let xingqi = fistDate.getDay();
    //渲染几个空白
    this.setData({
      nbspLength:xingqi,
    })
    //渲染有多少天出来
  },
count(){
    let month=this.data.month;
    let allDay = this.data.allDay;
    let year=this.data.year;
    if (month != 2) {
      if (month == 4 || month == 6 || month == 9 || month == 11){
        //判断是否是相同天数的几个月，二月除外
        this.setData({
          allDay: 30
        })
      }else{
        this.setData({
          allDay: 31
        })
      }
    }else{
      if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)){
        //判断是否是闰年，进行相应的改变
        this.setData({
          allDay: 29
        })
      }else{
        this.setData({
          allDay: 28
        })
      }
    }
  },
 lastMonth(){
    //上个月的操作逻辑
    if (this.data.month>1) {
      this.setData({
        month: this.data.month-1
      })
    } else {
      this.setData({
        month: 12,
        year: this.data.year-1,
      })
    }
    this.showday();
  },
  nextMonth(){
    //下个月的操作逻辑
    if (this.data.month < 12) {
      this.setData({
        month: this.data.month+1
      })
    }else {
      this.setData({
        month:1,
        year:this.data.year+1,
      })
    }
    this.showday();
  },
})